package com.naiterui.ehp.bs.patient.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.naiterui.ehp.bp.domain.DoctorCharge;
import com.naiterui.ehp.bp.utils.lang.StringUtil;
import com.naiterui.ehp.bs.patient.dao.IDoctorChargeDao;
import com.naiterui.ehp.bs.patient.repository.IApDoctorChargeRepository;

/**
 * 医生诊费设置持久化实现
 *
 * @author Amber
 * @since 1.0.0
 */
@Component
public class ApDoctorChargeDaoImpl implements IDoctorChargeDao {

    @Autowired
    private IApDoctorChargeRepository doctorChargeRepository;

    @Override
    public DoctorCharge getCharge(Long doctorId, int type) {
        return doctorChargeRepository.findFirstByDoctorIdAndChargeType(doctorId, type);
    }

    @Override
    public List<DoctorCharge> getChargeList(Set<Long> drids, int type) {
        if (drids != null && drids.size() > 0) {
            return doctorChargeRepository.findByDoctorIdInAndChargeType(drids, type);
        }
        return null;
    }

    @Override
    public Map<Long, DoctorCharge> getChargeMap(List<Long> doctorIdList, int type) {
        Map<Long, DoctorCharge> chargeMap = new HashMap<>();
        String drIds = StringUtil.convertListToStr(doctorIdList);
        if (StringUtils.isNotEmpty(drIds)) {
            List<DoctorCharge> charges = doctorChargeRepository.findByDoctorIdInAndChargeType(doctorIdList, type);
            for (DoctorCharge charge : charges) {
                chargeMap.put(charge.getDoctorId(), charge);
            }
        }
        return chargeMap;
    }
}
